﻿@using SW.Lite.Core.Extensions
@model List<SW.Lite.Model.Master.AdminModel>
@{
    Layout = "~/Areas/Master/Views/Shared/_Layout.cshtml";
}
@section Header{
    <link type="text/css" href="@Url.Content("~/Areas/Master/Common/js/jimgareaselect/css/imgareaselect-default.css")" rel="stylesheet" />
    <script type="text/javascript" src="@Url.Content("~/Areas/Master/Common/js/jimgareaselect/jquery.imgareaselect.min.js")"></script>
    <script type="text/javascript">
        function add() {
            $("#addDialog").dialog({
                title: '添加管理员',
                modal: true,
                width: 600,
                buttons: [
                    {
                        text: "确定",
                        click: function () {
                            Utils.ajax({
                                url: '@Url.Action("Add")',
                                data: { 'UserName': $('#UserName').val(), 'Password': $('#Password').val(), 'NickName': $('#NickName').val(), 'Face': $('#Face').val() },
                                type: 'POST',
                                success: function (d) { location.reload(); },
                                error: function (status) { }
                            });
                        }
                    }, {
                        text: '取消',
                        click: function () {
                            $(this).dialog("close");
                        }
                    }
                ]
            });
        }

        function deleteAll() {
            Utils.confirm('请确认', '确定删除此管理员吗？', function () {
                var menuIDs = [];
                $('.cboItem').each(function (i, n) {
                    menuIDs.push($(n).val());
                });

                if (menuIDs.length < 0) {
                    Utils.alert('消息', '请选择要删除的管理员！');
                    return;
                }

                Utils.ajax({
                    url: '@Url.Action("Delete")',
                    action: 'ADD',
                    data: { 'ids': menuIDs.join(',') },
                    type: 'POST',
                    success: function (d) {
                        if (d.Result) {
                            Utils.alert('消息', '已删除', function () {
                                location.reload();
                            });
                        }
                    },
                    error: function (status) { }
                });
            });
        }

        function setImg(filePath) {
            $('#FaceImgContainer').append($('<img src="' + filePath.replace(/~/g, "") + '" />'));
            $('#Face').val(filePath);
        }

        function adminRole() {
            var adminIDs = [];
            $('.cboItem:checked').each(function (i, n) {
                adminIDs.push($(n).val());
            });
            if (adminIDs.length != 1) {
                Utils.alert('消息', '请选择要查看角色权限的管理员，且只能选择一个人！');
                return;
            }
            location.href = '@Url.Action("Role")?ID=' + adminIDs[0];
        }
    </script>
}
<div class="panel grid_8">
    <div class="panel-header">
        <span class="i-24 i-user">管理员管理</span>
    </div>
    <div class="panel-body">
        <div class="panel-toolbar top clearfix">
            <ul>
                <li><a id="btnAdd" class="ic-16 ic-add" onclick="add();">添加</a></li>
                <li><a id="btnEdit" class="ic-16 ic-edit" onclick="edit();">修改</a></li>
                <li><a id="btnAdd" class="ic-16 ic-group" onclick="adminRole();">角色管理</a></li>
                <li><a id="btnDelete" class="ic-16 ic-cross" onclick="deleteAll();">删除</a></li>
            </ul>
        </div>
        <div class="dataTables_wrapper">
            <table id="roleTable" class="datatable-fn table">
                <thead>
                    <tr>
                        <th style="width: 30px;">
                            <input type="checkbox" onchange="Utils.checkAll(this.checked);" />
                        </th>
                        <th style="width: 200px;">管理员</th>
                        <th style="width: auto;">昵称</th>
                        <th style="width: 100px;">登录次数</th>
                        <th style="width: 120px;">最后登录IP</th>
                        <th style="width: 180px;">最后登录时间</th>
                    </tr>
                </thead>
                <tbody>
                    @foreach (var item in Model)
                    {
                        <tr>
                            <td class="center">
                                <input class="cboItem" type="checkbox" value="@item.Id" />
                            </td>
                            <td class="center">@item.UserName</td>
                            <td class="center">@item.NickName</td>
                            <td class="center">@item.LoginCount</td>
                            <td class="center">@item.LastLoginIP</td>
                            <td class="center">@item.LastLoginTime</td>
                        </tr>
                    }
                </tbody>
            </table>
            <div class="dataTables_paginate paging_full_numbers">
                <span>
                    @Html.Pager(20, (int)ViewBag.RecordCount)
                </span>
            </div>
        </div>
    </div>
</div>
<div id="addDialog" class="hide">
    <div style="float: left; width: 250px;">
        <div id="FaceImgContainer" style="border: 1px solid black; width: 240px; height: 300px; margin-bottom: 20px;">
        </div>
    </div>
    <div style="float: left; width: 300px;">
        <div class="form-inline form">
            <div class="form-row">
                <label>用户名</label>
                <div class="form-item large">
                    <input id="UserName" type="text" class="textinput" />
                </div>
            </div>
            <div class="form-row">
                <label>密码</label>
                <div class="form-item large">
                    <input id="Password" type="password" class="textinput" />
                </div>
            </div>
            <div class="form-row">
                <label>重复密码</label>
                <div class="form-item large">
                    <input id="PasswordRepeat" type="password" class="textinput" />
                </div>
            </div>
            <div class="form-row">
                <label>昵称</label>
                <div class="form-item large">
                    <input id="NickName" type="text" class="textinput" />
                </div>
            </div>
            <input type="hidden" id="Face" name="Face" />
        </div>
    </div>
    <div class="clear"></div>
</div>
